function Debug() {
	this.panelName = "___DEBUG___";
	this.panel = null;
//	this.size = 1024 * 1024;
	this.bufferedMsg = "";
	this.createPanel();
}

Debug.prototype.print = function(msg) {
	// format message
	var date = new Date();
	if( "" == this.bufferedMsg ) {
		msg = "[" + date + "]: " +msg;
	} else {
		msg = "<br/>[" + date + "]: " +msg;
	}
	
	// Add this message to buffered message
	this.bufferedMsg += msg;

	// If the panel still is null, that means the body element does not exist.
	if( null == this.panel ) {
		return;
	}
};

Debug.prototype.createPanel = function() {
	_this = this;
	if( null == document.body ) {
		setTimeout(function() {
			_this.createPanel();
		}, 1000);
		return null;
	}

	// Create debug panel
	var divPanel = document.createElement("div");
	divPanel.id = this.panelName;
	divPanel.style.display = "none";
	divPanel.style.backgroundColor = '#FFFFE6';
	divPanel.style.border = '1px solid #666666';
	divPanel.style.color = '#666666';
	divPanel.style.overflow = 'auto';
	divPanel.style.height = '200px';
	
	// Add panel to body
	document.body.appendChild(divPanel);

	document.body.ondblclick = function() {
		var panel = document.getElementById(_this.panelName);
		panel.innerHTML = _this.bufferedMsg;
		if( panel.style.display == 'none' ) {
			panel.style.display = 'block';
		} else {
			panel.style.display = 'none';
		}
	};

	return divPanel;
};

//Debug.prototype.setSize = function(size) {
//	this.size = size;
//};

Debug.debug = new Debug();
Debug.print = function(msg) {
	Debug.debug.print(msg);
}